<!--库存统计分析-->
<template>
  <div class="app-container">
    <!--多选框-->
    <el-form
      label-position="left"
      label-width="300px"
      :rules="rules"
      style="padding:0px 0px 0px 0px"
    >
      <el-row>
        <el-col >
          <el-button type="primary" @click="sortBySupplier()">按供应商排序</el-button>
          <el-button type="primary" @click="sortByDate()">按时间排序</el-button>
          <el-select
            clearable
            style="margin-left: 10px"
            placeholder="分组选择"
            v-model = "select_value"
            multiple
          >
            <el-option
              v-for="item in my_options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
          <el-button type="success" @click="analyse()">解析</el-button>
          <el-button type="primary" @click="fuckOut()">导出</el-button>

          <el-form-item >
            <span>当前应付金额</span>
            <el-input style="width: 200px" placeholder="无需填写"  v-model="nowNeedPayMoney" maxlength="150" ></el-input>
            <el-button type="primary" @click="sumarryAllMoney()" style="margin-bottom: 10px">汇总</el-button>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <el-form-item >
            <span>按供应商筛选</span>
            <el-input style="width: 200px"  v-model="filter_supplier_name" maxlength="150" ></el-input>
            <el-button type="primary" @click="filterByName()" style="margin-bottom: 10px">筛选</el-button>
          </el-form-item>
          <el-form-item >
            <span>按日期筛选</span>
            <el-date-picker
              v-model="filter_date"
              type="datetimerange"
              align="right"
              start-placeholder="开始日期"
              value-format="yyyy/MM/dd"
              format="yyyy/MM/dd"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '00:00:00']">
            </el-date-picker>
            <el-button type="primary" @click="filterByDate()" style="margin-bottom: 10px">筛选</el-button>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col>

        </el-col>
      </el-row>

      <el-row>
        <el-col>

        </el-col>
      </el-row>


    </el-form>

    <!--   筛选 -->
    <span> &#12288 </span>

    <el-table
      v-loading = "listLoading"
      :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
      element-loading-text="Loading"
      border
      fit
      max-height="580"
      highlight-current-row
      :row-class-name="tableRowClassName"
    >
      <el-table-column align="center" label="供应商名称" >
        <template slot-scope="techlist">
          <span>{{techlist.row.supplierName}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="订单编号"  prop="date" >
        <template slot-scope="techlist">
          <span>{{techlist.row.orderNumber}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="物料编码" >
        <template slot-scope="techlist" >
          <span>{{techlist.row.materialNumber}}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="物料名称" prop="date">
        <template slot-scope="techlist">
          <span>{{techlist.row.materialName}}</span>
        </template>
      </el-table-column>

      <el-table-column label="图号"  align="center" prop="address">
        <template slot-scope="techlist">
          <span>{{techlist.row.drawingNo}}</span>
        </template>
      </el-table-column>

      <el-table-column label="规格"  align="center" prop="address">
        <template slot-scope="techlist">
          <span>{{techlist.row.spec}}</span>
        </template>
      </el-table-column>

      <el-table-column label="品牌" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span>{{techlist.row.brand}}</span>
        </template>
      </el-table-column>

      <el-table-column label="订货数量" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.predeterminedNumber}}</span>
        </template>
      </el-table-column>

      <el-table-column label="含税单价" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.priceWithTax}}</span>
        </template>
      </el-table-column>

      <el-table-column label="价税合计" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.priceTaxGather}}</span>
        </template>
      </el-table-column>

      <el-table-column label="应付金额" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.amountDue}}</span>
        </template>
      </el-table-column>

      <el-table-column label="入库金额" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.inventoryDate}}</span>
        </template>
      </el-table-column>

      <el-table-column label="到票日期" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.ticketComeTime}}</span>
        </template>
      </el-table-column>

      <el-table-column label="应付日期" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.needPayDate}}</span>
        </template>
      </el-table-column>


      <el-table-column label="预计付款日期" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.expectPayDate}}</span>
        </template>
      </el-table-column>

      <el-table-column label="预计付款金额" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.needPayAmount}}</span>
        </template>
      </el-table-column>

      <el-table-column label="税点" align="center" :show-overflow-tooltip="true" >
        <template slot-scope="techlist">
          <span >{{techlist.row.taxPoint}}</span>
        </template>
      </el-table-column>

    </el-table>




    <el-pagination
      align = "center"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :page-size="pagesize"
      layout="total, prev, pager, next"
      :total="list.length">
    </el-pagination>


  </div>
</template>


<style>
  .el-form-item{
    display: inline-block !important ;
  }

  .el-form-item__label{
    display: none;
    width: 0px !important;
  }
  .dialog-font{
    font-weight: bold;
  }

  .el-form-item__content{
    margin-left: 3px !important;
    margin-right: 3px !important;
  }

  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
  .demo-table-expand .el-dialog-c .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 100%;
  }

  .sortSpan{
    font-size: 16px;
  }




</style>


<script>
  import { getList } from '@/api/table'
  import axios from 'axios';
  import Qs from 'qs' //引入json
  import { parseDateFull } from '@/api/DateFor';
  import VueClipboard from 'vue-clipboard2'

  export default {

    filters: {
      statusFilter(status) {
        const statusMap = {
          published: 'success',
          draft: 'gray',
          deleted: 'danger'
        }
        return statusMap[status]
      }
    },
    data() {
      return {
        //筛选内容//
        filter_supplier_name:'',
        filter_date:[],
        ////
        nowNeedPayMoney:'',
        //排序单选框的内容(分组)
        select_value:[],//多选数据
        select_time:'',
        select_money:'',
        //排序单选框的选项
        sortValue:'',
        bB:[true,true,true,true,true,true,true],
        form_inventory:{
          thisUse:0,
          needBuy:0,
          inventory:0,
          inventoryremark:'',
          id:'',
          index:'',
        },
        my_options:[
        ],
        time_select_options:[{
          value:'',
          label:''
        },{
          value:'',
          label:''
        },{
          value:'',
          label:''
        }],
        form:{
          dialogFigureNumber:'',
          dialogSpec:'',
          dialogbrand:'',
          dialogBomRema:''
        },
        formLabelWidth: '120px',
        dialogFormVisible:false,
        inventorydialogFormVisible:false,
        showInventory: false,
        showBuy:true, //显示本次购买的一列
        canUse: true,
        //用于筛选的数据
        filterContent: '',
        A_filterContent:'',
        A_filterListContent:'',//列表筛选
        //分页数据
        currentPage:1, //初始页
        pagesize:20,    //每页的数据
        rules: {},
        //本次购买:
        //退货数量
        //多选框
        list: [],
        changedList:[], //经过变动的list
        buylist:[],//{购买的material号,机台号，时间，个数，购买还是退货}
        listCopy:[],
        listLoading: false,
        recordeList:[],//用来记录本身的大List
      }
    },
    created() {
      // this.select_value = this.my_options[0].value;
      this.init();
    },
    methods: {

      sumarryAllMoney(){
        axios.get("/payment-plan/summary").then( res => {
          if(res.data.code == "20000"){
            this.nowNeedPayMoney = res.data.data;
          }

        })
      },

      //通过供应商筛选
      filterByName(){
        let data = {"supName":this.filter_supplier_name};
        axios.post("/payment-plan/filter_supplierName",data).then(res =>{
          let arr = [...JSON.parse(res.data.data)];
          this.list = arr;
        })
      },

      //通过供应商筛选
      filterByDate(){
        let data = {"fil_date":this.filter_date};
        axios.post("/payment-plan/filter_by_date",data).then(res =>{
            let arr = [...JSON.parse(res.data.data)];
            this.list = arr;
        })
      },


      handleCopyLink(row){
        console.log(row);  //每一行的数据
        let bomRemark = row.bomRemark;  //每一行的某个值，如选中的当前行的url
        var oInput = document.createElement('input');     //创建一个隐藏input（重要！）
        oInput.value = bomRemark;    //赋值
        console.log(oInput.value);
        document.body.appendChild(oInput);
        oInput.select(); // 选择对象
        document.execCommand("Copy"); // 执行浏览器复制命令
        oInput.className = 'oInput';
        oInput.style.display='none';
        this.$message({
          message: '复制成功',
          type: 'success'
        });
      },
      startSort(){
        let that = this;
        if(this.sortValue == '时间递减'){
          this.list.sort(function(a,b){
            return that.parseDate(b.delivery) > that.parseDate(a.delivery) ? 1 : -1;
          })
        }else if(this.sortValue == '时间递增'){
          this.list.sort(function(a,b){
            return that.parseDate(b.delivery) > that.parseDate(a.delivery) ? -1 : 1;
          })
        }else if(this.sortValue == ''){
          let data = {"thislist":this.list,"item":""};
          this.listLoading = true;
          debugger
          axios.post("/material/sort",data).then(res =>{
            if(res.data.code === "20000"){
              this.list = [...JSON.parse(res.data.data)];
            }
            this.listLoading = false;
          }).catch( f => {
            this.listLoading = false;
          })
        }
      },
      setBatch(i){
        this.bB = [true,true,true,true,true,true,true];
        this.bB[i] = false;
      },

      showInventoryD(row){
        debugger
        this.inventorydialogFormVisible = true;
        this.form_inventory.needBuy = row.unpurchased;
        this.form_inventory.inventory = row.inventory;
        this.form_inventory.inventoryremark = row.inventoryRemark;
        this.form_inventory.id = row.id;
        this.form_inventory.thisUse = "";
        this.form_inventory.index = row.index;

      },
      showD(row){
        this.dialogFormVisible = true;
        this.form.dialogSpec = row.specs;
        this.form.dialogFigureNumber = row.figureNo;
        this.form.dialogbrand = row.brand;
        this.form.dialogBomRema = row.bomRemark;
      },
      parseDate(date){
        return parseDateFull(date);
      },
      getGroups(){
        axios.get("/payment-plan/groups").then((res) => {
          this.listLoading = false;
          if(res.data.code === '20000'){
            debugger
            let arr = [...JSON.parse(res.data.data)];
            for(var i = 0; i < arr.length;i++){
              console.log(arr[i]);
              // this.my_options.push([arr[i],arr[i]]);
              this.my_options.push({label:arr[i],value:arr[i]});
            }
            console.log(this.my_options);
            debugger
          }
        })
      },
      useInventory(){
        var myDate = new Date();
        let datefull = parseDateFull(myDate);
        this.$confirm('确认使用库存？').then( _ => {

          axios.get("/material/changeInventory",{
            params:{
              id: this.form_inventory.id,
              thisUse: this.form_inventory.thisUse,
              inventoryRemark : this.form_inventory.inventoryremark == undefined ? "" : this.form_inventory.inventoryremark + datefull + "\n",
            },
          }).then( res => {
            if(res.data.code == "20000"){
              this.form_inventory.needBuy = this.form_inventory.needBuy - this.form_inventory.thisUse;
              for(var i = 0; i < this.list.length;i++){//让此id的值变掉，让此id的库存备注掉
                if(this.form_inventory.id == this.list[i].id){
                  this.list[i].unpurchased = this.list[i].unpurchased - this.form_inventory.thisUse;
                  this.list[i].inventoryRemark =  this.form_inventory.inventoryremark == undefined ? "" : this.form_inventory.inventoryremark + "\n" + datefull + "\n";
                }
              }
              this.$message({
                message: '用库存成功',
                type: 'success'
              });
            }
            this.inventorydialogFormVisible = false;//消失
            this.listLoading = false;
          }).catch( res => {
                this.listLoading = false;
              }
          )
        }).catch( _ =>{

        })
      },
      //生成唯一15位字符
      getUUIDAndStorage(){
        let num =this.randomWord(false,30);
      },
      randomWord(randomFlag, min, max){
        var str = "",
            range = min,
            arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
        // 随机产生
        if(randomFlag){
          range = Math.round(Math.random() * (max-min)) + min;
        }
        for(var i=0; i<range; i++){
          pos = Math.round(Math.random() * (arr.length-1));
          str += arr[pos];
        }
        return str;
      },
      //页面高亮的处理,传进来row和index
      tableRowClassName({row, rowIndex}) {

        row.index = rowIndex;

        if (row.isUrgent == true) {  //如果是加急的话就这样
          return 'warning-row';
        }

        if(row.unpurchased === 0){
          return 'success-row';
        }
        return '';
      },
      //分页
      handleSizeChange: function (size) {
        this.pagesize = size;
        console.log(this.pagesize)  //每页下拉显示数据
      },
      handleCurrentChange: function(currentPage){
        this.currentPage = currentPage;
        console.log(this.currentPage)  //点击第几页
      },
      analyse(){
        this.listLoading = true;
        let data = {"groups":this.select_value};
        axios.post("/payment-plan/analyse",data).then((res) => {
              debugger
              this.listLoading = false;
              if(res.data.code === '20000'){
                debugger
                let arr = [...JSON.parse(res.data.data)];
                this.list = arr;
                debugger
                this.recordeList = JSON.parse(JSON.stringify(this.list));//作记录数组用
              }
            }
        )
      },
      fuckOut(){//导出
        axios.get("/payment-plan/downloadExcel",{
          responseType:'blob'
        }).then( response => {//TODO导出存在问题
          let blob = new Blob([response.data],{type:'application/octet-stream'});
          let link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          var fiName = "付款计划";
          var F = fiName + ".xls";
          console.log(F);
          link.download = F;
          link.click();
        })
      },
      filterhandler(){
        if(this.select_value == '' || this.select_value === null){//搞成完整的list
          this.list = JSON.parse(JSON.stringify(this.recordeList));
          return;
        }
        debugger
        let newlist = this.recordeList.filter( x => {
          return x.group == this.select_value;
        });
        this.list = newlist;
      },
      Acode_List_filterHandler(){
        let tmpList = [];
        let thatList = this.list;
        debugger
        for(var i = 0; i < thatList.length ; i++){
          let No = this.list[i].materialNo;
          let ct = this.A_filterListContent;
          if(No.indexOf(ct) != -1 ){
            debugger
            tmpList.push(this.list[i]);
          }
        }
        tmpList.map(x => x.backGoods = '');
        this.list = tmpList;
        console.log(this.list);
      },
      sortByDate(){
        this.listLoading = true;
        axios.get("/payment-plan/sortByD").then( res => {
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            this.list = arr;
          }
          this.listLoading = false;
        }).catch( res => {
              this.listLoading = false;
            }
        )
      },
      sortBySupplier(){
        this.listLoading = true;
        axios.get("/payment-plan/sortByS").then( res => {
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            this.list = arr;
          }
          this.listLoading = false;
        }).catch( res => {
              this.listLoading = false;
            }
        )
      },
      init(){
        this.listLoading = true;
        axios.get("/payment-plan/get-all-POD").then( res => {
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            this.list = arr;
          }
          this.listLoading = false;
          this.getGroups();
        }).catch( res => {
              this.listLoading = false;
            }
        )
      },
      //输入本次购买之后 需购加上 已购减去
      clickbuy(row){
      },
      //点击退货之后 处理退货的内容
      backgoodsSolve(row){
        if(row.backGoods){
          //退货后
          // row.purchased =  String(parseInt(row.purchased) - parseInt(row.backGoods));
          // row.unpurchased = String(parseInt(row.unpurchased) + parseInt(row.backGoods));
          // row.quantity = String( parseInt(row.quantity) - parseInt(row.backGoods));
          // this.changedList.push(row)
          // row.backGoods = '';
        }
      },
      clearCart(){
        this.listLoading = true;
        axios.get('/cart-goods/clearCart',{
          params:{
            userName: localStorage.getItem("userName")
          },
        }).then( res =>{
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            console.log(arr);
            this.list = arr;
            this.canUse = true;
          }else if(res.data.code == "40000"){
            this.logout();
            this.$alert(res.data.data);
          }
          this.listLoading = false;
        }).catch( res => {
          this.listLoading = false;
        })
      },
      buyCart(){
        this.setBatch(0);
        this.listLoading = true;
        axios.get("/cart-goods/getMyCart",{
          params:{
            userName: localStorage.getItem("userName")
          },
        }).then( res => {
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            console.log(arr);
            this.list = arr;
          }else if(res.data.code == "40000"){
            this.logout();
            this.$alert(res.data.data);
          }
          this.listLoading = false;
        }).catch( res => {
              this.listLoading = false;
              this.logout();
            }
        )
      },
      async logout() {
        localStorage.removeItem('hasLogin')
        this.$router.push(`/login?redirect=${this.$route.fullPath}`)
      },
      //获得已完成的，即需购小于0
      getHaveFinished(){
        this.setBatch(3);
        this.listLoading = true;

        axios.get("/material/getHaveFinishedBuy",{
          params:{
            content: this.filterContent
          },
        }).then( res => {
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            arr.map(x => x.backGoods = '');
            this.list = arr;
            this.showBuy = false; //置本次购买那一列为null
            this.showInventory = true;
          }
          this.listLoading = false;
        }).catch( res => {
              this.listLoading = false;
            }
        )
      },
      //获得需购为0的
      getNeedBuyZero(){
        this.setBatch(2);
        this.listLoading = true;
        this.canUse = true;
        this.showInventory = false;
        axios.get("/material/allPruchased",{
          params:{
            content: this.filterContent
          },
        }).then( res => {
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            arr.map(x => x.backGoods = '');
            this.list = arr;
            this.showBuy = false; //置本次购买那一列为null
          }
          this.listLoading = false;
        }).catch( res => {
              this.listLoading = false;
            }
        )
      },
      filterUrgent(){
        this.setBatch(1);
        this.listLoading = true;
        axios.get("/material/urgentfilter",{
          params:{
            content: this.filterContent
          },
        }).then( res => {
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            arr.map(x => x.backGoods = '');
            console.log(arr);arr.map(x => x.backGoods = '');
            this.list = arr;
          }
          this.listLoading = false;
        }).catch( res => {
              this.listLoading = false;
            }
        )
      },
      //填充本次购买
      fillThisPurchase(){
        for(var row = 0; row < this.list.length ;row++){
          this.list[row].thisPurchase = this.list[row].unpurchased;
          this.$set(this.list,row,this.list[row]);//更新此行数据
        }
      },
      clearAllThisPurchase(){
        for(var row = 0; row < this.list.length ;row++){
          this.list[row].thisPurchase = '';
          this.$set(this.list,row,this.list[row]);//更新此行数据
        }
      },
      //经过本次购买和退货数量，最终的结果推回后端
      pushPurchase_back2Sever(){
        this.changedList = [];
        this.listLoading = true;
        this.showInventory = false;
        for(var row = 0; row < this.list.length ;row++){
          debugger
          if(this.list[row].thisPurchase){
            this.list[row].purchased =  String(parseInt(this.list[row].thisPurchase) + parseInt(this.list[row].purchased));
            this.list[row].unpurchased = String(parseInt(this.list[row].unpurchased) - parseInt(this.list[row].thisPurchase));
            this.changedList.push(this.list[row])
            this.buylist.push(
                {
                  "id":this.list[row].id,
                  "materialNo": this.list[row].materialNo,
                  "ACode":this.list[row].ACode,
                  "time":this.list[row].delivery,
                  "buy_num":this.list[row].thisPurchase,
                  // "back_num":"",
                  "productId":this.list[row].productId,
                })
          }
          if(this.list[row].backGoods){
            this.list[row].purchased =  String(parseInt(this.list[row].purchased) - parseInt(this.list[row].backGoods));
            this.list[row].unpurchased = String(parseInt(this.list[row].unpurchased) + parseInt(this.list[row].backGoods));
            this.changedList.push(this.list[row])
            this.buylist.push(
                {
                  "id":this.list[row].id,
                  "materialNo": this.list[row].materialNo,
                  "ACode":this.list[row].ACode,
                  "time":this.list[row].delivery,
                  // "buy_num":"",
                  "back_num":this.list[row].backGoods,
                  "productId":this.list[row].productId,
                })
            // row.quantity = String( parseInt(row.quantity) - parseInt(row.backGoods));   等待上传Bom表平内容
          }
        }
        let data = {"userName":localStorage.getItem("userName"),"buyArrSimple":this.buylist};
        axios.post('/cart-goods/buyMaterial',data)
            .then( res => {
              if(res.data.code == "20000"){
                for(var i=0; i < this.list.length; i++){
                  this.list[i].thisPurchase = '';
                  this.list[i].backGoods = '';
                }
                for(var j = 0; j < this.list.length;j++){
                  this.list[j].thisPurchase = '';
                  this.list[j].backGoods = '';
                }
                this.$alert("更新成功");
                this.buylist=[];
              }else if(res.data.code == "40000"){
                this.$alert(res.data.data);
              }
              this.listLoading = false;
            }).catch( f=>{
          this.listLoading = false;
        } )
      },
      //列表内的值重置到全部的值(重置按钮)
      reset2AllData(){
        this.listLoading = true;
        this.canUse = true;
        this.showInventory = false;
        axios.get("/excel/reset",{
          params:{
            content: this.filterContent
          },
        }).then( res => {
          if(res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            console.log(arr);
            this.list = arr;
            this.showBuy = true;
          }
          this.listLoading = false;
        }).catch( res => {
              this.listLoading = false;
            }
        )
      },
      //导出excel
      export2buy(){
        this.canUse = true;
        axios.get('/cart-goods/getPurchaseExcel',{
          responseType: 'blob',
          params:{
            userName:localStorage.getItem("userName"),
          }
        }).then((response) =>{
          if(response == null){
            this.$alert("无此用户,导出失败");
            this.logout();
          }
          let blob = new Blob([response.data],{type:'application/octet-stream'});
          let link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          link.download = "采购.xls";
          link.click();
          // this.list = [];
          this.$alert("导出成功");
        }).catch( f=>{
              this.$alert("尚未登陆,请登录后使用")
              this.logout();
            }
        );
      },
      openM() {
        this.$alert("导出成功");
      },
      fetchData() {
        this.setBatch(4);
        this.listLoading = true;
        axios.get('/material/getFilterMaterial').then( (res) => {
          if (res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            arr.map(x => x.backGoods = '');
            this.list = arr;
            debugger
            this.listCopy = this.list;
          }
          this.canUse = true;
          this.listLoading = false;
        }).catch(f =>{
          this.canUse = true;
          this.listLoading = false;
        })
      },
      fetchinventory() {
        this.setBatch(5);
        this.listLoading = true;
        axios.get('/material/inventoryfilter').then( (res) => {
          if (res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            arr.map(x => x.backGoods = '');
            this.list = arr;
            debugger
            this.listCopy = this.list;
          }
          this.canUse = true;
          this.listLoading = false;
        }).catch(f =>{
          this.canUse = true;
          this.listLoading = false;
        })
      },
      fetchAll(){
        this.setBatch(6);
        this.listLoading = true;
        axios.get('/material/getAllMaterial').then( (res) => {
          if (res.data.code == "20000"){
            let arr = [...JSON.parse(res.data.data)];
            arr.map(x => x.backGoods = '');
            this.list = arr;
            debugger
            this.listCopy = this.list;
          }
          this.canUse = true;
          this.listLoading = false;
        }).catch(f =>{
          this.canUse = true;
          this.listLoading = false;
        })
      },
      //退出登录
      async logout() {
        localStorage.removeItem('hasLogin');
        this.$router.push(`/login?redirect=${this.$route.fullPath}`);
      },



    }
  }
</script>
